﻿using HCMS.CommonDtos;
using HCMS.Extensions;
using HCMS.IServices.Manage;
using Microsoft.AspNetCore.Mvc;

namespace HCMS.Web.Manage.Controllers.Module.Logs
{
    /// <summary>
    /// 管理员 登录 日志
    /// </summary>
    public class AdminLoginLogsController : ModuleController
    {
        private readonly IAdminLoginLogsAppService adminLoginLogsAppService;

        public AdminLoginLogsController(
            IAdminLoginLogsAppService adminLoginLogsAppService)
        {
            this.adminLoginLogsAppService = adminLoginLogsAppService;
        }

        #region 列表
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult List()
        {
            return View($"{BasePath}/Logs/AdminLoginLogs/List.cshtml");
        }

        /// <summary>
        /// 列表 Ajax
        /// </summary>
        /// <returns></returns>
        [ActionName("List")]
        [HttpPost]
        public async Task<IActionResult> PostList()
        {
            var searchArgs = new SearchArgsDto()
            {
                SearchName = Request.Form["searchName"].ToString(""),
                SearchKey = Request.Form["searchKey"].ToString(""),

                TimeStart = Request.Form["searchDateStart"].ToString(""),
                TimeEnd = Request.Form["searchDateEnd"].ToString("")
            };

            var pager = new PagerArgsDto()
            {
                CurrentPageIndex = Request.Form["page"].ToInt(1),
                PageSize = Request.Form["limit"].ToInt(10)
            };

            var result = await adminLoginLogsAppService.ManageList(searchArgs, pager);

            return Json(new { code = 0, data = result.Data, count = result.PagerInfo.RowCount, msg = "ok" });
        }
        #endregion
    }
}
